package com.yocard.yxyd.http;

import com.yocard.yxyd.utils.util.CacheDoubleStaticUtils;
import com.yocard.yxyd.utils.util.StringUtils;
import com.yocard.yxyd.base.Constants;

import java.io.IOException;

import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.Response;

/**
 * Created on 2018/9/26.
 */
public class AuthInterceptor implements Interceptor {

    @Override
    public Response intercept(Chain chain) throws IOException {
        Request request = chain.request();
        String token = CacheDoubleStaticUtils.getString(Constants.KEY_TOKEN);
        if (!StringUtils.isEmpty(token)) {
            Request.Builder builder = request.newBuilder();
            builder.addHeader("Authorization", " Bearer "+CacheDoubleStaticUtils.getString(Constants.KEY_TOKEN));
            request = builder.build();
        }
        return chain.proceed(request);
    }
}
